package com.chinasofti.map;

import java.util.HashMap;
import java.util.Map;

public class Demo02 {
    public static void main(String[] args) {

        Map<String,String> map = new HashMap<>();

        //put(K key , V value)
        map.put("K1","V1");
        map.put("K2","V2");
        map.put("K3","V3");
        map.put("K4","V4");
        map.put("K5","V5");
        //method1(map);
        //method2(map);
        //method3(map);
        //method4(map);
        //method5(map);
        //method6(map);
        //method7(map);
    }
    private static void method7(Map<String, String> map) {
        //集合的长度
        int size = map.size();
        System.out.println("size = " + size);
    }

    private static void method6(Map<String, String> map) {
        //判断集合是否为空
        boolean b1 = map.isEmpty();
        System.out.println("b1 = " + b1);
        map.clear();
        boolean b2 = map.isEmpty();
        System.out.println("b2 = " + b2);
    }

    private static void method5(Map<String, String> map) {
        //判断集台是否包含指定的值
        boolean bl = map.containsValue("V1") ;
        System. out.println("bl = " + bl) ;
        boolean b8 = map.containsValue("y8") ;
        System. out.println("b8 = " + b8) ;
    }

    private static void method4(Map<String, String> map) {
        //判断集合是否包含指定的链
        boolean b2 = map.containsKey("K2") ;
        boolean b8 = map.containsKey("k7");
        System. out.println("b2 = " + b2) ;
        System. out.println("b8 = "+ b8);
    }

    private static void method3(Map<String, String> map) {
        //移除全部键值对
        map.clear() ;
        System. out.println("map = " + map) ;
    }

    private static void method2(Map<String, String> map) {
        //删除键
        String k1 = map.remove("K1");
        System.out.println("k1 = " + k1);
        System.out.println(map);
    }

    private static void method1(Map<String, String> map) {
        //如果要添加的链不存在，那会会把链值都添加到集合中
        //如果要添加的键存在，那么会覆盖原先的值,把原先的值
        //作为返回值进行返回
        String s = map.put("K5","v6");

        System.out.println("s = " + s);

        System.out.println(map);
    }
}
